package com.ts.notice.config;

import org.mapstruct.Qualifier;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DelayMQConfig {
    // 声明业务Exchange
    @Bean
    public DirectExchange delayExchange(){
        return new DirectExchange("delay-Exchange");
    }

    // 创建延时队列
    @Bean
    public Queue delayQueue() {
        HashMap<String, Object> args = new HashMap<>();
        // 声明队列绑定的死信交换机x-dead-letter-exchange
        args.put("x-dead-letter-exchange", "deadLetterExchange");
        // 声明队列的属性路由key
        args.put("x-dead-letter-routing-key", "dle.err");
        return QueueBuilder.durable("delay-queue").withArguments(args).build();
    }
    // 延时队列绑定关系
    @Bean
    public Binding businessBinding1(/*Queue delayQueue, DirectExchange delayExchange*/){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with("reg");
    }


    //声明死信Exchange
    @Bean
    public TopicExchange deadLetterExchange(){
        return new TopicExchange("deadLetterExchange");
    }

    // 声明死信队列
    @Bean
    public Queue deadLetterQueue(){
        return new Queue("dle-queue",true,false,false,null);
    }

    // 死信队列绑定交换机
    @Bean
    public Binding deadLetterQueueBinding(Queue deadLetterQueue, TopicExchange deadLetterExchange){
        return BindingBuilder.bind(deadLetterQueue).to(deadLetterExchange).with("dle.*");
    }
   /* *
     * 延时队列所绑定的交换机

    @Bean
    public CustomExchange delayExchange() {
        //创建一个自定义交换机，可以发送延迟消息
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("delay-Exchange", "x-delayed-message", true, false, args);
    }

    *
     * 延时队列

    @Bean
    public Queue delayQueue() {
        return new Queue("delay-Queue");
    }
    *
     * 延迟队列绑定交换器

    @Bean
    public Binding bindingDelayCustomExchangeQueue(){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with("nologin").noargs();
    }*/




}
